#!/usr/bin/env node

const http = require('http');
const {join} = require('path');
const fs = require('fs');
const mem = require('memory-format');

http.createServer((req,res)=>{
    console.time('TEST');
    let file =join( __dirname,req.url);
    console.log(fs.existsSync(file));
    if(!fs.existsSync(file)) {
        res.end(`${req.url} not exists!`);
        return;
    }

    fs.readFile(file,(err,data) =>{
        if(err) {
            res.end('something wrong!');
        }else {
            console.log(mem());
            console.timeEnd('TEST');
            res.end(data);
        }
    })
}).listen(8080);
